<!DOCTYPE html >

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Pagination 分页表格</title>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

		<script src="__PUBLIC__/scripts/boot.js" type="text/javascript"></script>

	</head>
	<body>
		<h1>会议记录</h1>
		<div style="width:900px;">
			<div class="mini-toolbar" style="border-bottom:0;padding:2px;">
				<table style="width:100%;">
					<tr>
						<td style="width:100%;"><a class="mini-button" iconCls="icon-add" onclick="add()">增加</a><a class="mini-button" onclick="ExportExcel()">导出Excel</a><td style="white-space:nowrap;"><span>项目名称</span>
						<input type="text" id="key1"  />
						<span>内容</span>
						<input type="text" id="key2"  />
						<input type="button" value="查找" onclick="search()"/>
						</td>
					</tr>
				</table>
			</div>
		</div>

		<div id="datagrid1" class="mini-datagrid" style="width:900px;height:400px;"
		url="__APP__/Project/querymeeting"  idField="id" allowResize="true"
		sizeList="[20,30,50,100]" pageSize="20"
		>
			<div property="columns">
				<div type="indexcolumn" >
					序号
				</div>
				
				<div field="pname" width="120" headerAlign="center" allowSort="true">
					项目名称
				</div>
				<div field="date" width="120" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd">
					日期
				</div>
				<div field="content" width="120" headerAlign="center" allowSort="true">
					内容
				</div>
			</div>
		</div>

		<iframe id="exportIFrame" style="display:none;"></iframe>

		<div id="win1" class="mini-window" title="详细内容" style="width:800px;"
		showMaxButton="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
		>

			<fieldset style="width:700px;border:solid 1px #aaa;margin-top:8px;position:relative;">
				<legend>
					详细信息
				</legend>
				<div id="editForm1" style="padding:5px;">
					<input class="mini-hidden" name="idmeetinglog"/>
					<table style="width:100%;">
						<tr>
							<td style="width:80px;">项目名称</td>
							<td style="width:150px;">
							<input id="pname" name="pname" class="mini-textbox" />
							</td>
						</tr>
						<tr>
							<td style="width:80px;">日期</td>
							<td style="width:150px;">
							<input name="date" class="mini-datepicker" format="yyyy-MM-dd" />
							</td>
						</tr>
						<tr>
							<td>内容：</td>
							<td>
							<input id="content" name="content" class="mini-textarea"  style="width:400px;height:300px"/>
							</td>
						</tr>
						<tr>
							<td></td>
							<td>
							<a class="mini-button" iconCls="icon-save" plain="true" onclick="updateForm()">保存</a> 
							</td>
							
						</tr>
					</table>
				</div>
			</fieldset>
		</div>

		<div id="win2" class="mini-window" title="新增会议记录" style="width:800px;"
		showMaxButton="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
		>

			<fieldset style="width:700px;border:solid 1px #aaa;margin-top:8px;position:relative;">
				<legend>
					新增会议记录
				</legend>
				<div id="addForm1" style="padding:5px;">

					<table style="width:100%;">
						<tr>
							<td style="width:80px;">项目名称</td>
							<td style="width:150px;">
							<input   class="mini-autocomplete" required="true" style="width:200px;"
							valueField="text" textField="text" textName="pname"
							url="__APP__/Filter/pname"  value="{$_SESSION['pname']}" text="{$_SESSION['pname']}">
							</td>
						</tr>
						<tr>
							<td style="width:80px;">日期</td>
							<td style="width:150px;">
							<input id="date" name="date" class="mini-datepicker" format="yyyy-MM-dd" />
							</td>
						</tr>
						<tr>
							<td>内容：</td>
							<td>
							<input id="content" name="content" class="mini-textarea"  style="width:400px;height:300px"/>
							</td>
						</tr>
						<tr>
							<td>
							<input value="发送" type="button" onclick="addForm()" />
							</td>
							<td>
							<input value="重置" type="button" onclick="resetForm()"/>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>
		</div>
		<script type="text/javascript">
			mini.parse();

			var grid = mini.get("datagrid1");

			grid.load();

			var t = mini.get("date");

			///////////

			var a = new Date();
			var b = 8-a.getDay();
			if(a.getDay()==0)
				b=1;


			var nextdate = new Date (new Date().getTime () + b*24 * 3600 *1000);


			///////

			t.setValue(nextdate);

			grid.on("rowclick", function(e) {
				//alert(e.record.mid);//弹个ID出来就好了

				showWindow();
			});

			var db = new mini.DataBinding();
			db.bindForm("editForm1", grid);

			
			$("#key1").bind("keydown", function(e) {
				if(e.keyCode == 13) {
					search();
				}
			});
			$("#key2").bind("keydown", function(e) {
				if(e.keyCode == 13) {
					search();
				}
			});
			function showWindow() {
				var win = mini.get("win1");
				win.show();
			}

			//对"createtime"字段，进行降级排序
			grid.sortBy("idmeetinglog", "desc");

			function search() {
				var key1 = document.getElementById("key1").value;
				var key2 = document.getElementById("key2").value;
				//mini.alert(state);
				grid.load({
					key1 : key1,
					key2 : key2
				});
			}


			
			///////////////////////////////////////////////////////
			function add() {
			if(checkauth()) {
					var win = mini.get("win2");
					win.show();
				}
			}

			function delRow(row_uid) {
				var row = grid.getRowByUID(row_uid);

				if(row) {
					if(confirm("确定删除此记录？")) {
						grid.loading("删除中，请稍后......");
						$.ajax({
							url : "__APP__/Mail/delete?mid=" + row.mid,
							success : function(text) {

								grid.reload();
							},
							error : function() {
							}
						});
					}
				}
			}
		function ExportExcel() {
        var columns = grid.getBottomColumns();
         columns = columns.clone();
        for (var i = columns.length - 1; i >= 0; i--) {
                    var column = columns[i];
                    if (!column.field) {
                        columns.removeAt(i);
                    } else {
                        var c = { header: column.header, field: column.field };
                        columns[i] = c;
                    }
         }
        
         var data = grid.getData();      //获取表单多个控件的数据
         var json = mini.encode(data);   //序列化成JSON
         var header = mini.encode(columns); 
            //mini.alert(data[0]['mid']);
         window.location.href="__APP__/File/excel?header="+header+"&data="+json;

        }
			function ExportExcel_backup() {
				var tablename = "meetinglog";
				var filename = "例会纪要";
				window.location.href = "__APP__/File/exportexcel?tablename=" + tablename + "&filename=" + filename;
			}
			function getForm() {
			//提交表单数据
            var form = new mini.Form("#editForm1");  
            form.validate();
            if (form.isValid() == false) return;
			
            var data = form.getData();      //获取表单多个控件的数据
            var json = mini.encode(data);   //序列化成JSON
			mini.alert(json);
        	}
		
			function updateForm() {
				//提交表单数据
				var form = new mini.Form("#editForm1");
				var data = form.getData(true);
				//获取表单多个控件的数据

				$.ajax({
					url : "__APP__/Project/updatemeeting",
					type : "post",
					data : {
						Data : data
					},
					success : function(text) {
						alert("提交成功");
						grid.reload();
						var win = mini.get("win1");
						win.hide();
					}
				});

			}
			function addForm() {
				//提交表单数据
				var form = new mini.Form("#addForm1");
				var data = form.getData(true);
				//获取表单多个控件的数据

				$.ajax({
					url : "__APP__/Project/addmeeting",
					type : "post",
					data : {
						Data : data
					},
					success : function(text) {
						alert("提交成功");
						grid.reload();
						var win = mini.get("win2");
						win.hide();
					}
				});

			}

			function resetForm() {
				var form = new mini.Form("#addForm1");
				form.reset();
			}

			function CloseWindow(action) {

				if(window.CloseOwnerWindow)
					window.CloseOwnerWindow(action);
				
				else
					window.close();

			}

			function checkauth() {
				
					return true;
			}
		</script>

	</body>
</html>